import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pyecharts import Pie
plt.rcParams['font.sans-serif'] = ['SimHei'] # 在matplotlib中设置字体为SimHei黑体
plt.rcParams['axes.unicode_minus'] = False# 解决matplotlib坐标轴负号‘-’显示为方块问题
df = pd.read_csv(r"C:\Users\gcc\Desktop\quanguo2.csv")
def drawbar():
    lis=[]
    lis=list(df['景区所在地'])
    dic={}
    for i in lis:
        dic[i]=dic.get(i,0)+1
    print(dic)
    key=dic.keys()
    value=dic.values()
    plt.figure(figsize=(10,5))
    plt.bar(key,value)
    plt.xticks(rotation=-45)
    plt.xlabel("省份")
    plt.ylabel("景点个数")
    plt.title("全国景点个数统计表")
    plt.tight_layout()#F防止标签显示不全
    for x,y in enumerate(value):
      plt.text(x-0.25,y+0.1,'%s'%int(y))
    plt.show()
def drawpie():
    lis = []
    lis = list(df['景区所在地'])
    dic = {}
    for i in lis:
        dic[i] = dic.get(i, 0) + 1
    print(dic)
    key = dic.keys()
    value = dic.values()
    pie=Pie("全国景点分布",title_pos='center',width=800,height=500)
    pie.add("",key,value,is_label_show=True,is_more_utils=True,center=['52%','50%'],is_legend_show=True,legend_top="6%",legend_pos="left",legend_orient="vertical")
    pie.render(path="cpie.html")
def drawqipao():
    a=df[df['游客满意度(百分制)']>94]
    a=a.loc[:,['景区所在地','游客满意度(百分制)','游客点评数']]
    b=a.groupby(a['景区所在地']).count()
    c=a['游客点评数'].groupby(a['景区所在地']).sum()
    x=list(c.index)#设置x
    y=list(b['游客满意度(百分制)'])#设置y
    size=list((c.values.astype(np.int))/100)#设置气泡大小和好评数有关
    color=np.random.rand(len(x))
    plt.figure(figsize=(10,5))
    plt.scatter(x,y,s=size,c=color,alpha=0.6)
    plt.xticks(rotation=45)
    for i in range(len(x)):
      plt.text(x[i],y[i],x[i],color='r',rotation=15)
    plt.xlabel("省份")
    plt.ylabel('好评率>95景点个数')
    plt.tight_layout()
    plt.show()
    print(size)
drawpie()
